<%@ page import="com.lczyfz.istep.common.constants.DistributeType" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>教学管理管理</title>
	<meta name="decorator" content="default"/>

	<script type="text/javascript" src="${path}/js/common/jquery.min.js"></script>

	<script src="${path}/static/jquery-jbox/2.3/jquery.jBox-2.3.js"></script>
	<script src="${path}/static/jquery-jbox/2.3/jquery.jBox-2.3.src.js"></script>

	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$('#distributeClass').selectpicker({
				'selectedText': 'cat'
			});
			$('#distributeStudent').selectpicker({
				'selectedText': 'cat'
			});
		});

		function selectTrainProgramName(findAllTrainProgramNameId){
			$.ajax({
				type: "POST",
				url: "${ctx}/teach/teachDistribute/findDistributeListById",
				data: {
					trainProgramId:findAllTrainProgramNameId.options[findAllTrainProgramNameId.selectedIndex].value
				},
				success:function(json){
				$(".resetDuallist").empty();
				var list = json.dataObj;
				for(var i=0;i<list.CourseSystemList.length;i++)
				{
					$("#CourseSystemList").append("<option value='"+ list.CourseSystemList[i].id+"'>"+list.CourseSystemList[i].coursesystemName+"</option>");
				}
				for(var j=0;j<list.CtfSetList.length;j++)
				{
					$("#CtfSetList").append("<option value='"+ list.CtfSetList[j].id+"'>"+list.CtfSetList[j].ctfSetName+"</option>");
				}
				for(var t=0;t<list.PaperList.length;t++)
				{
					$("#PaperList").append("<option value='"+ list.PaperList[t].id+"'>"+list.PaperList[t].paperName+"</option>");
				}
				$(".resetDuallist").bootstrapDualListbox('refresh');
				},
				error:function(){
					alertx("error");
				}
			});
		}

		function checkForm() {
			var distributeName = $("#distributeName").val();
			var distributeClass = $("#distributeClass").val();
			var distributeStudent = $("#distributeStudent").val();
			var findAllTrainProgramNameId = $("#findAllTrainProgramNameId").val();
			var CourseSystemList = $("#CourseSystemList").val();
			var CtfSetList = $("#CtfSetList").val();
			var PaperList = $("#PaperList").val();
			if(distributeName==null || distributeName=="" ){
				window.alertx("请填写下发名称！");
				return false;
			}
			if( (distributeClass==null || distributeClass=="") && (distributeStudent==null || distributeStudent=="") ){
				window.alertx("请选择下发对象！");
				return false;
			}
			if(distributeClass!=null && distributeStudent!=null ){
				window.alertx("添加下发只能选择班级或者学生！");
				return false;
			}
			if( (CourseSystemList==null || CourseSystemList=="") && (CtfSetList==null || CtfSetList=="") && (PaperList==null || PaperList=="")){
				window.alertx("请选择下发内容！");
				return false;
			}
//			if($('table tr').length <= 1){
//				window.alertx("请点击右侧确认选择按钮确认下发内容！");
//				return false;
//			}

			//拼接课程体系id
			var CourseSystem_str="";
			$('table #CourseSystemBody tr').find('td:eq(0)').each(function() {
				CourseSystem_str += $(this).text() + ",";
			});
			$("#CourseSystemString").val((CourseSystem_str.substring(0,CourseSystem_str.length-1)).split(","));
			//拼接CTF题目集id
			var CtfSet="";
			$('table #CtfSetBody tr').find('td:eq(0)').each(function() {
				CtfSet += $(this).text() + ",";
			});
			$("#CtfSetString").val((CtfSet.substring(0,CtfSet.length-1)).split(","));


		}

		//确认选择按钮-课程体系
		function confirmCourseSystem(){
//			alertx($('#CourseSystemList').val().toString());
			$.ajax({
				type: "POST",
				url: "${ctx}/teach/teachDistribute/getCourseSystemNameById",
				data: {
					"CourseSystemId": $('#CourseSystemList').val().toString()
				},
				success:function(CourseSystemListName){
					console.log(CourseSystemListName);
					$('#CourseSystemBody').html("");
					for(var i=0; i<CourseSystemListName.length; i++){
						$("#CourseSystemBody").append("<tr><td hidden>"+ CourseSystemListName[i].id +"</td><td>"+ CourseSystemListName[i].name +"</td><td>课程体系</td><td>无</td></tr>");
					}
				},
				error:function(){
					alertx("error");
				}
			});
		}
		//确认选择按钮-CTF题目集
		function confirmCtfSet(){
			var findAllTrainProgramNameId = $("#findAllTrainProgramNameId").val();
			$.ajax({
				type: "POST",
				url: "${ctx}/teach/teachDistribute/getCtfSetListNameById",
				data: {
					"CtfSetId": $('#CtfSetList').val().toString()
				},
				success:function(CtfSetListName){
					$('#CtfSetBody').html("");
					for(var i=0; i<CtfSetListName.length; i++){
//						$("#CtfSetBody").append("<tr><td hidden>"+ CtfSetListName[i].id +"</td><td>"+CtfSetListName[i].name +"</td><td>CTF题目集</td><td><a href='javascript:configCtfSetBox()'>配置</a></td></tr>");
						$("#CtfSetBody").append("<tr><td hidden>"+ CtfSetListName[i].id +"</td><td>"+CtfSetListName[i].name +"</td><td>CTF题目集</td><td><a href='javascript:configCtfSetBox("+ CtfSetListName[i].id +")'>配置</a></td></tr>");
					}
				},
				error:function(){
					alertx("error");

				}
			});
		}
		//确认选择按钮-试卷
		function confirmPaper(){
			var findAllTrainProgramNameId = $("#findAllTrainProgramNameId").val();
			$.ajax({
				type: "POST",
				url: "${ctx}/teach/teachDistribute/getPaperListNameById",
				data: {
					"PaperId": $('#PaperList').val().toString()
				},
				success:function(PaperListName){
					$('#PaperBody').html("");
					for(var i=0; i<PaperListName.length; i++){
						$("#PaperBody").append("<tr><td hidden>"+ PaperListName[i].id +"</td><td>"+PaperListName[i].name +"</td><td>试卷</td><td><a href='javascript:configPaper()'>配置</a></td></tr>");
					}
				},
				error:function(){
					alertx("error");
				}
			});
		}

		function configCtfSetBox(CtfSetId){
			top.$.jBox("<div class='form-search' style='padding-left:20px; padding-top: 20px; padding-bottom: 15px;'>是否可以查看解题思路</div>"+
					"<div class='form-search' style='padding-left:30px; padding-bottom: 20px;'><input type='radio' id='solutionYes' name='solutionIsAllowRadio' value='0'/>是<br/>"+
					"<input type='radio' id='solutionNo' name='solutionIsAllowRadio' value='1' checked='checked'/>否</div>",
					{
						title: "配置CTF题目集",
						submit: function (v, h, f) {
							alertx("CtfSetId: "+ CtfSetId +"   solutionIsAllow: "+ f.solutionIsAllowRadio);
							$("#solutionIsAllow").val(f.solutionIsAllowRadio);

						}
					});
			return false;
		}

		<%--function configPaperBox(){--%>
			<%--top.$.jBox(--%>
					<%--"<form:form id='searchForm' modelAttribute='teachExam' action='#' method='post' class='breadcrumb form-search'>"+--%>
						<%--"考试科目名称：<input type='text' id='examName' name='examName'/><br/>"+--%>
						<%--"考试开始时间：<input type='text' id='beginDate' name='beginDate' class='input-mini Wdate beginDateInput' style='width: 150px' value='<fmt:formatDate value="${teachExam.beginDate}" pattern="yyyy-MM-dd HH:mm:ss"/>' onclick='WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});'/><br/>"+--%>
						<%--"考试结束时间：<input type='text' id='endDate' name='endDate' class='input-mini Wdate endDateInput' style='width: 150px' value='<fmt:formatDate value="${teachExam.endDate}" pattern="yyyy-MM-dd HH:mm:ss"/>' onclick='WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});'/><br/>"+--%>
						<%--"答题时间：<input type='text' id='answerTime' name='answerTime'/><br/>"+--%>
						<%--"可参加考试次数：<input type='text' id='examFrequency' name='examFrequency'/><br/>"+--%>
						<%--"是否可以查看答题情况：<input type='radio' id='checkAnswerYes' name='ifCheckAnswer' value='0'/>是<input type='radio' id='checkAnswerNo' name='ifCheckAnswer' value='1' checked='checked'/>否"+--%>
					<%--"</form:form>",--%>

					<%--{--%>
						<%--title: "配置试卷",--%>
						<%--submit: function (v, h, f) {--%>
							<%--alertx("hahaha"+ f.examName);--%>

						<%--}--%>
					<%--});--%>
			<%--return false;--%>
		<%--}--%>

	</script>

	<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" type="text/css" media="all">
	<link href="${path}/css/common/bootstrap-duallistbox.css" rel="stylesheet" type="text/css"/>
	<script type="text/javascript" src="${path}/js/common/jquery.bootstrap-duallistbox.js"></script>

	<%--下拉多选控件--%>
	<link rel="stylesheet" href="${path}/css/common/bootstrap-select.min.css" />
	<script type="text/javascript" src="${path}/js/common/bootstrap-select.min.js" ></script>

	<style>
		.control-label{font-weight: normal;}
		#distributeName{ height: 30px;}
	</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/teach/teachDistribute/">教学管理列表</a></li>
		<li class="active"><a href="${ctx}/teach/teachDistribute/form?id=${teachDistribute.id}">下发<shiro:hasPermission name="teach:teachDistribute:edit">${not empty teachDistribute.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="teach:teachDistribute:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="teachDistribute" action="${ctx}/teach/teachDistribute/addDistributeList" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<%--<div class="control-group" >--%>
			<%--<a href='javascript: configCtfSetBox()'>配置CTF题目集</a>--%>
			<%--&lt;%&ndash;<a href='javascript: configPaperBox()'>配置试卷</a>&ndash;%&gt;--%>
			<%--<input class="btn" type="button" value="弹框" onclick="return promptx('弹框','姓名')"/>--%>

		<%--</div>--%>
		<div class="control-group">
			<label class="control-label">下发名称：</label>
			<div class="controls">
				<form:input path="distributeName" htmlEscape="false" maxlength="100" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">下发班级：</label>
			<div class="col-sm-4">
				<select id="distributeClass" name="distributeClass" class="selectpicker show-tick form-control" multiple data-live-search="false">
					<c:forEach items="${findAllClassName}" var="findAllClassName">
						<option value="${findAllClassName.id}">${findAllClassName.className}</option>
					</c:forEach>
				</select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">下发学生：</label>
			<div class="col-sm-4">
				<select id="distributeStudent" name="distributeStudent" class="selectpicker show-tick form-control" multiple data-live-search="false">
					<c:forEach items="${findAllStudentName}" var="findAllStudentName">
						<option value="${findAllStudentName.id}">${findAllStudentName.name}</option>
					</c:forEach>
				</select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">培训方案：</label>
			<div class="controls">
				<select id="findAllTrainProgramNameId" name="findAllTrainProgramNameId" class="required input-medium" onChange="selectTrainProgramName(this)">
					<option value="" selected>====请选择====</option>
					<c:forEach items="${findAllTrainProgramName}" var="findAllTrainProgramName">
						<option value="${findAllTrainProgramName.id}" >${findAllTrainProgramName.trainprogramName}</option>
					</c:forEach>
				</select>
			</div>
		</div>

		<span class="help-inline" style="margin-left: 188px"><font color="red">* 以下选项至少选一个</font> </span>

		<div class="control-group">
			<label class="control-label">课程体系：</label>
			<div class="controls">
				<div class="container"></div>
				<div class="col-lg-10 col-md-9 col-sm-9 col-xs-12">
					<select multiple="multiple" size="10" id="CourseSystemList" name="CourseSystemList" class="resetDuallist">
						<c:forEach var="AllCourseSystemName" items="${findAllCourseSystemName}">
							<option value="${AllCourseSystemName.id}"
									<c:if test="${AllCourseSystemName.isChoose=='true'}">selected</c:if> >${AllCourseSystemName.coursesystemName}</option>
						</c:forEach>
					</select>
				</div>
				<%--<span class="help-inline" ><font color="red">*</font> </span>--%>
				<%--<input id="btnCourseSystem" class="btn btn-primary" type="button" value="确认选择" style="margin-top: 10%;" onclick="return confirmCourseSystem()"/>--%>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">CTF题目集：</label>
			<div class="controls">
				<div class="container"></div>
				<div class="col-lg-10 col-md-9 col-sm-9 col-xs-12">
					<select multiple="multiple" size="10" id="CtfSetList" name="CtfSetList" class="resetDuallist">
						<c:forEach var="AllCtfSetName" items="${findAllCtfSetName}">
							<option value="${AllCtfSetName.id}"
									<c:if test="${AllCtfSetName.isChoose=='true'}">selected</c:if> >${AllCtfSetName.ctfSetName}</option>
						</c:forEach>
					</select>
				</div>
				<%--<span class="help-inline" ><font color="red">*</font> </span>--%>
				<%--<input id="btnCtfSet" class="btn btn-primary" type="button" value="确认选择" style="margin-top: 10%;" onclick="return confirmCtfSet()"/>--%>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">试卷：</label>
			<div class="controls">
				<div class="container"></div>
				<div class="col-lg-10 col-md-9 col-sm-9 col-xs-12">
					<select multiple="multiple" size="10" id="PaperList" name="PaperList" class="resetDuallist">
						<c:forEach var="AllPaperName" items="${findAllPaperName}">
							<option value="${AllPaperName.id}"
									<c:if test="${AllPaperName.isChoose=='true'}">selected</c:if> >${AllPaperName.paperName}</option>
						</c:forEach>
					</select>
				</div>
				<%--<span class="help-inline" ><font color="red">*</font> </span>--%>
				<%--<input id="btnPaper" class="btn btn-primary" type="button" value="确认选择" style="margin-top: 10%;" onclick="return confirmPaper()"/>--%>
			</div>
		</div>
		<%--<div class="control-group">--%>
			<%--<div class="controls">--%>
				<%--<table id="contentTable" class="table table-striped table-bordered table-condensed">--%>
					<%--<thead>--%>
					<%--<tr>--%>
						<%--<th hidden>下发id</th>--%>
						<%--<th>已选择下发内容</th>--%>
						<%--<th>下发类型</th>--%>
						<%--<shiro:hasPermission name="teach:teachDistribute:edit"><th>配置</th></shiro:hasPermission>--%>
					<%--</tr>--%>
					<%--</thead>--%>
					<%--<tbody id="CourseSystemBody"></tbody>--%>
					<%--<tbody id="CtfSetBody"></tbody>--%>
					<%--<tbody id="PaperBody"></tbody>--%>
				<%--</table>--%>
			<%--</div>--%>
		<%--</div>--%>
		<div class="control-group">
			<label class="control-label">备注信息：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge "/>
			</div>
		</div>

		<input id="CourseSystemString" name="CourseSystemString" type="hidden"/>
		<input id="CtfSetString" name="CtfSetString" type="hidden"/>
		<input id="PaperString" name="PaperString" type="hidden"/>

		<input id="solutionIsAllow" name="solutionIsAllow" type="hidden"/>

		<div class="form-actions">
			<%--<shiro:hasPermission name="teach:teachDistribute:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="添 加" onclick="return checkForm();"/>&nbsp;</shiro:hasPermission>--%>
			<%--<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>--%>
			<input id="btnSubmit" class="btn btn-primary" type="submit" value="下一步" onclick="return checkForm();"/>
		</div>
	</form:form>

	<script>
		var demo1 = $('select[class="resetDuallist"]').bootstrapDualListbox({infoTextFiltered: '<span class="label label-purple label-lg">Filtered</span>'});
		$("#demoform").submit(function() {
			alert($('[class="resetDuallist"]').val());
			return false;
		});
	</script>
</body>
</html>